package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.enums.CollectionOriginalTypeEnum;
import com.sc.nft.mapper.CollectionGiftMapper;
import com.sc.nft.entity.CollectionGift;
import com.sc.nft.service.CollectionGiftService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 藏品赠送(CollectionGift)表Dao层
 *
 * @author 王伟成
 * @since 2024-03-16 15:19:26
 */
@Slf4j
@Repository
public class CollectionGiftDao extends ServiceImpl<CollectionGiftMapper, CollectionGift> {

    public List<CollectionGift> getCollectionId(Long id) {
        LambdaQueryWrapper<CollectionGift> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CollectionGift::getCollectionId, id);
        wrapper.eq(CollectionGift::getOriginalType, CollectionOriginalTypeEnum.MATE_UNIVERSE);
        return this.list(wrapper);
    }
    public void deleteByCollectionId(Long collectionId) {
        LambdaUpdateWrapper<CollectionGift> wrapper = Wrappers.lambdaUpdate();
        wrapper.eq(CollectionGift::getCollectionId,collectionId);
        this.remove(wrapper);
    }

    public List<CollectionGift> getConfListByCollectionIdAndType(Long id, CollectionOriginalTypeEnum originalType) {
        LambdaQueryWrapper<CollectionGift> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CollectionGift::getCollectionId, id);
        wrapper.eq(CollectionGift::getOriginalType, originalType);
        return this.list(wrapper);
    }
    public CollectionGift getConfListByCollectionIdAndTypeAnd(Long id, CollectionOriginalTypeEnum originalType,Integer consumeType) {
        LambdaQueryWrapper<CollectionGift> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CollectionGift::getCollectionId, id);
        wrapper.eq(CollectionGift::getOriginalType, originalType);
        wrapper.eq(CollectionGift::getConsumeType, consumeType);
        wrapper.orderByDesc(CollectionGift::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
}
